#!/bin/bash

#MYSQL8
MYSQL_DIR=install_mysql
MYSQL_NAME=mysql-8.0.31-linux-glibc2.17-x86_64-minimal
MYSQL_DRIVER_CLASS=com.mysql.cj.jdbc.Driver
MYSQL_DRIVER=mysql-connector-j-8.0.31.jar
MYSQL_HOME=${workspace}/${MYSQL_NAME}
MYSQL_USERNAME=root
MYSQL_PASSWORD=B#2008_2108#es
MYSQL_PORT=6603
MYSQL_INNODB_BUFFER_POOL_SIZE=2048
MYSQL_USER=${USER}
MYSQL_IP=192.168.3.104

function remotemysqlexecute()
{
        ${MYSQL_HOME}/bin/mysql -u${MYSQL_USERNAME} -p${MYSQL_PASSWORD} --socket ${MYSQL_HOME}/mysql.sock -e "$1"
}

function remotemysqlsource()
{
        cp $2 ${MYSQL_HOME}/bin
        sleep 1
        SQL_FILE=`echo $2 | awk -F "/" '{print $NF}'`
        ${MYSQL_HOME}/bin/mysql -u${MYSQL_USERNAME} -p${MYSQL_PASSWORD} --socket ${MYSQL_HOME}/mysql.sock $1 < ${MYSQL_HOME}/bin/${SQL_FILE}
        sleep 1
        rm -f ${MYSQL_HOME}/bin/${SQL_FILE}
        sleep 1
}

function cpmysqldriver()
{
        echo "复制MySQL数据库驱动文件..."
        cp -r ${INSTALL_DIR}/${MYSQL_DIR}/${MYSQL_DRIVER} $1
}

function checkenvironment()
{
        echo "####检查环境及用到的软件####"
        listComd="tar zip unzip sed java jar"
        for i in $listComd
        do
                type $i 2>/dev/null >./1.tmp
                if [ -s ./1.tmp ] ; then
                        continue;
                else
                        echo "$i Commdon is not installded !"
                        exit 1;
                fi
        done
        echo "############################"
        rm -f ./1.tmp
        sleep 1
}

